package com.gitee.feizns.quickstart.web.ex.impl;

import com.gitee.feizns.quickstart.domain.vo.Ret;
import com.gitee.feizns.quickstart.web.ex.NotFoundException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

/**
 * 找不到资源的异常处理器
 * @author feizns
 * @since 2023/04/20
 */
public class NotFoundExceptionHandler extends AbstractExceptionHandler<NotFoundException> {

    /**
     * 没有找到状态
     */
    private final HttpStatus notFoundStatus;

    public NotFoundExceptionHandler(HttpStatus notFoundStatus) {
        this.notFoundStatus = notFoundStatus;
    }

    @Override
    public ResponseEntity<Ret<?>> handle(NotFoundException e) {
        return ResponseEntity.status(notFoundStatus)
                .body(Ret.error(HttpStatus.NOT_FOUND.value(), e.getMessage()));
    }

}
